package com.yilin.medical.lsh;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.annotation.SuppressLint;


/**
 * Created by liushenghan1 on 15/3/3.
 */
public class BaseBean implements Serializable {

	private static final long serialVersionUID = -4450277591477618729L;

	protected SimpleException simpleException;

	public SimpleException getSimpleException() {
		return simpleException;
	}

	public void setSimpleException(SimpleException simpleException) {
		this.simpleException = simpleException;
	}

	@SuppressLint("DefaultLocale")
	public Object get(String key) {
		String methodName = "get" + key.substring(0, 1).toUpperCase()
				+ key.substring(1);
		Object result = null;
		try {

			Method method = ((Object) this).getClass().getMethod(methodName,
					new Class[] {});
			result = method.invoke(this, new Object[] {});
		} catch (NoSuchMethodException e) {

			Logs.i("BaseBean","字段" + key + "没有对应的get方法");
					
			try {
				Field field = ((Object) this).getClass().getDeclaredField(key);
				field.setAccessible(true);
				result = field.get(this);
			} catch (NoSuchFieldException e1) {
				Logs.i("BaseBean","类" + ((Object) this).getClass().getName() + "没有字段："
						+ key);
				e.printStackTrace();
				e1.printStackTrace();
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (IllegalArgumentException e1) {
				e1.printStackTrace();
			}

		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return result;
	}
}
